<?php
namespace app\app\controller\v1;

use app\app\model\VideoModel;
use think\Db;
use app\app\util\OnlineUtils;

class VideoController extends BaseController{

    /**
     * @return array
     * 获取视频列表
     */
    public function VideoList(){
        $video = new VideoModel();
        try{
            $list  = $video->getList();
        }catch (Exception $e){
            return jsonReturn(402,'获取失败',$this->error());
        }
        return jsonReturn(200,'success',$list);
    }

    /**
     * video详情
     */
    public function VideoDetail(){
        $id = input('get.id');
        $video = new VideoModel();
        try{
            $data = $video->getOne($id);
        }catch (Exception $e){
            return jsonReturn(402,'获取失败');
        }
        return jsonReturn(200,'success',$data);
    }


    /**
     * 点赞video
     */
    public function VideoClick(){
        $user_id = OnlineUtils::getUserIdBySid();
        $id = input('get.id')?input('get.id'):'';
        if($id == ''){
            return jsonReturn(402,'参数不齐');
        }
        $video = new VideoModel();
        $video->user_id = $user_id;
        $video->click($id);
        return jsonReturn(200,'success');
    }


    /**
     * 留言
     */
    public function message(){
        $user_id = OnlineUtils::getUserIdBySid();
        $data = input('post.');
        $video = new VideoModel();
        $video->user_id = $user_id;
        try{
            $video->leaveMessage($data);
        }catch (Exception $e){
            return jsonReturn(402,'留言失败');
        }
        return jsonReturn(200,'success');
    }
}